﻿using hoemwork;
using System;
using System.Collections.Generic;
using System.Text;

namespace hoemwork
{
   
    class Time
    {
        

        public static void GetWeekParametmr()
        {
            DateTime year = new DateTime(2022, 1, 1);
            DateTime boundary = new DateTime();
            boundary = year.AddYears(1);
            ShowWeeksin(GetFirstMonday(year), boundary);
            GetDate(year, 17, TimeUnit.day);
        }

        public static DateTime GetDate(DateTime start, int mount, TimeUnit time)
        {
            switch (time)
            {
                case TimeUnit.day:
                    return start = start.AddDays(mount);
                case TimeUnit.week:
                    return start = start.AddDays(mount * 7);
                case TimeUnit.year:
                    return start = start.AddYears(mount);
                default:
                    return DateTime.MinValue;
            }

        }
        public static DateTime GetFirstMonday(DateTime year)
        {
            DateTime Monday = new DateTime();
            while (year.DayOfWeek != DayOfWeek.Monday)
            {
                Monday = (year = year.AddDays(1));
            }

            Console.WriteLine(Monday);
            return Monday;
        }
        /// <summary>
        /// boundary边界
        /// </summary>
        /// <param name="year"></param>
        /// <param name="boundary"></param>
        public static void ShowWeeksin(DateTime year, DateTime boundary)
        {
            int i = 0;
            while (year < boundary)
            {
                Console.WriteLine("第" + (i + 1) + "周:" + year.AddDays((i) * 7).ToShortDateString() + "-----" + year.AddDays((i + 1) * 7).ToShortDateString());
                i++;
                year = year.AddDays(7);
            }
        }
        public static DateTime GetDate(DateTime result, string AddCount, string AddUnit)
        {



            if ("月".IndexOf(AddUnit) > -1)
            {
                Console.WriteLine(result = result.AddMonths(Convert.ToInt32(AddCount)));
            }
            else
            {

            }
            if ("周".IndexOf(AddUnit) > -1)
            {
                Console.WriteLine(result = result.AddDays((Convert.ToInt32(AddCount)) * 7));
            }
            else
            {

            }
            if ("日".IndexOf(AddUnit) > -1)
            {
                Console.WriteLine(result = result.AddDays(Convert.ToInt32(AddCount)));
            }
            else
            {

            }
            if ("年".IndexOf(AddUnit) > -1)
            {
                Console.WriteLine(result = result.AddYears(Convert.ToInt32(AddCount)));
            }

            return result;

        }



    }


}

